﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Index</title>
    <link href='@Url.Content("~/Scripts/jPaginate/css/style.css")' rel="stylesheet" type="text/css" />
    <script src='@Url.Content("~/Scripts/jquery-1.5.1.min.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/jPaginate/jquery.paginate.js")' type="text/javascript"></script>
    <link href='@Url.Content("~/Content/Site.css")' rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var strSearchProperty = "";
        var strSearchCondition = "";
        var strSortProperty = "";
        var strSortCondition = "";
        var tmpCount = 1;
        var tempStart = 1;

        $(document).ready(function () {
            $.ajaxSetup({ cache: false });
            GetPaged();
        })

        function logout(id) {
            $.ajax({
                type: "POST",
                url: "/Evaluate/Logout",
                data: { id: id },
                success: function () {
                    alert("操作成功！");
                },
                error: function () {
                    alert("操作失败");
                },
                complete: function () {
                    UpdateRow(id);
                }
            })
        }

        function UpdateRow(id) {
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "/Evaluate/GetEvaluateByID",
                data: { id: id },
                success: function (json) {
                    if (json.sit == "未开始") {
                        var tdStr = "<td>" + json.dep + "</td><td>" + json.term + "</td><td>" + json.start + "</td><td>" + json.end + "</td><td>" + json.sit + "</td><td><a href='javascript:void(0);' onclick='logout(" + json.id + ")'>注销</a>丨<a href='/Evaluate/Update/" + json.id + "'>修改</a></td>";
                    } else if (json.sit == "评教中") {
                        var tdStr = "<td>" + json.dep + "</td><td>" + json.term + "</td><td>" + json.start + "</td><td>" + json.end + "</td><td>" + json.sit + "</td><td><span style=' color:Gray'>注销</span>丨<span style=' color:Gray'>修改</span></td>";
                    } else if (json.sit == "完成") {
                        var tdStr = "<td>" + json.dep + "</td><td>" + json.term + "</td><td>" + json.start + "</td><td>" + json.end + "</td><td>" + json.sit + "</td><td><span style=' color:Gray'>注销</span>丨<span style=' color:Gray'>修改</span></td>";
                    } else {
                        var tdStr = "<td>" + json.dep + "</td><td>" + json.term + "</td><td>" + json.start + "</td><td>" + json.end + "</td><td>" + json.sit + "</td><td><a href='javascript:void(0);' onclick='logout(" + json.id + ")'>激活</a>丨<a href='/Evaluate/Update/" + json.id + "'>修改</a></td>";
                    }
                    $("#tr" + id).empty();
                    $("#tr" + id).append(tdStr);
                },
                error: function (msg) {
                    alert(msg);
                }
            })
        }

        function GetPaged() {
            $.ajax({
                type: "GET",
                url: "/Evaluate/GetPaged",
                dataType: "json",
                data: { pageIndex: tempStart, pageSize: 10, strSearchProperty: strSearchProperty, strSearchCondition: strSearchCondition, strSortProperty: strSortProperty, strSortCondition: strSortCondition },
                success: function (json) {
                    var tabStr = "<table id='tabInfo' class='blueTable'><tr class='blueTableTitle'><td>系部</td><td>学期</td><td>开始时间</td><td>结束时间</td><td>状态</td><td>操作</td></tr>";
                    if (json != null) {
                        tmpCount = json[json.length - 1].count;
                        for (var i = 0; i < json.length - 1; i++) {
                            if (json[i].sit == "未开始") {
                                tabStr += "<tr id='tr" + json[i].id + "'><td>" + json[i].dep + "</td><td>" + json[i].term + "</td><td>" + json[i].start + "</td><td>" + json[i].end + "</td><td>" + json[i].sit + "</td><td><a href='javascript:void(0);' onclick='logout(" + json[i].id + ")'>注销</a>丨<a href='/Evaluate/Update/" + json[i].id + "'>修改</a></td></tr>";
                            } else if (json[i].sit == "评教中") {
                                tabStr += "<tr id='tr" + json[i].id + "'><td>" + json[i].dep + "</td><td>" + json[i].term + "</td><td>" + json[i].start + "</td><td>" + json[i].end + "</td><td>" + json[i].sit + "</td><td><span style=' color:Gray'>注销</span>丨<span style=' color:Gray'>修改</span></td></tr>";
                            } else if (json[i].sit == "完成") {
                                tabStr += "<tr id='tr" + json[i].id + "'><td>" + json[i].dep + "</td><td>" + json[i].term + "</td><td>" + json[i].start + "</td><td>" + json[i].end + "</td><td>" + json[i].sit + "</td><td><span style=' color:Gray'>注销</span>丨<span style=' color:Gray'>修改</span></td></tr>";
                            } else {
                                tabStr += "<tr id='tr" + json[i].id + "'><td>" + json[i].dep + "</td><td>" + json[i].term + "</td><td>" + json[i].start + "</td><td>" + json[i].end + "</td><td>" + json[i].sit + "</td><td><a href='javascript:void(0);' onclick='logout(" + json[i].id + ")'>激活</a>丨<a href='/Evaluate/Update/" + json[i].id + "'>修改</a></td></tr>";
                            }
                        }
                    } else {
                        tabStr += "<tr><td colspan='6'>没有满足条件的数据！</td></tr>";
                    }
                    tabStr += "</table>";
                    $("#divTab").append(tabStr);
                    $("#pageIndex").paginate({
                        count: tmpCount,
                        start: tempStart,
                        display: 10,
                        border: false,
                        text_color: '#79B5E3',
                        background_color: 'none',
                        text_hover_color: '#2573AF',
                        background_hover_color: 'none',
                        images: false,
                        mouse: 'press',
                        onChange: function (page) {
                            tempStart = page;
                            $("#divTab").empty();
                            GetPaged();
                        }
                    })
                },
                error: function (msg) {
                    alert(msg);
                }
            })
        }
    </script>
</head>
<body style=" margin:0px; border:0px;">
    <div class="Content">
        <div id="Top">
            <div id="divCreateUrl">
                <p>
                    @Html.ActionLink("新建评教", "Create")
                </p>
            </div>
            <div id="divSearch">
            </div>
        </div>
        <div id="divTab">
        </div>
        <div id="pageIndex" class="pageIndex" style="margin-top: 5px; width: 95%">
        </div>
    </div>
</body>
</html>
